(function (vc, vm) {
    vc.extends({
        data: {
            editAccountBankInfo: {
                bankId: '',
                bankCode: '',
                personName: '',
                personTel: '',
                bankName: '',
                shopId: ''
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('editAccountBank', 'openEditAccountBankModal', function (_params) {
                $that.refreshEditAccountBankInfo();
                $('#editAccountBankModel').modal('show');
                vc.copyObject(_params, $that.editAccountBankInfo);
                $that.editAccountBankInfo.shopId = vc.getCurrentCommunity().shopId;
            });
        },
        methods: {
            editAccountBankValidate: function () {
                return vc.validate.validate({
                    editAccountBankInfo: $that.editAccountBankInfo
                }, {
                    'editAccountBankInfo.bankCode': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "银行账号不能为空"
                        },
                        {
                            limit: "maxin",
                            param: "1,20",
                            errInfo: "银行账号超长了"
                        },
                    ],
                    'editAccountBankInfo.personName': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "持卡人不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "20",
                            errInfo: "持卡人名称不能超过20位"
                        },
                    ],
                    'editAccountBankInfo.personTel': [
                        {
                            limit: "phone",
                            param: "",
                            errInfo: "电话格式错误"
                        },
                    ],
                    'editAccountBankInfo.bankName': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "开户行不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "100",
                            errInfo: "开户行名称不能超过100位"
                        },
                    ],
                    'editAccountBankInfo.bankId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "银行ID不能为空"
                        }
                    ]
                });
            },
            editAccountBank: function () {
                if (!$that.editAccountBankValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                vc.http.apiPost(
                    '/accountBank/updateAccountBank',
                    JSON.stringify($that.editAccountBankInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#editAccountBankModel').modal('hide');
                            vc.emit('accountBankManage', 'listAccountBank', {});
                            vc.toast("修改成功");
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            refreshEditAccountBankInfo: function () {
                $that.editAccountBankInfo = {
                    bankId: '',
                    bankCode: '',
                    personName: '',
                    personTel: '',
                    bankName: '',
                    shopId: ''
                }
            }
        }
    });
})(window.vc, window.vc.component);
